package gupao_edu_spring_aop.aop.framework.adapter;

import gupao_edu_spring_aop.aopalliance.intercept.MYJoinPoint;
import gupao_edu_spring_aop.aopalliance.intercept.MYMethodInterceptor;
import gupao_edu_spring_aop.aopalliance.intercept.MYReflectiveMethodInvocation;

import java.lang.reflect.Method;

/**
 * @ClassName:
 * @Description:
 * @Auther: zhouych
 * @Date: 2019/5/10 14:27
 */
public class MYAfterReturningAdviceInterceptor extends MYAbstractAspectAdvice implements MYMethodInterceptor {


    private MYJoinPoint joinPoint;

    public MYAfterReturningAdviceInterceptor(Method aspectMethod, Object aspectTarget) {
        super(aspectMethod, aspectTarget);
    }

    @Override
    public Object invoke(MYReflectiveMethodInvocation methodInvocation) throws Throwable {
        Object retVal = methodInvocation.proceed();
        this.joinPoint = methodInvocation;
        this.afterReturning(retVal,methodInvocation.getMethod(),methodInvocation.getArguments(),methodInvocation.getThis());
        return retVal;
    }

    private void afterReturning(Object retVal, Method method, Object[] arguments, Object aThis) throws Throwable {
        super.invokeAdviceMethod(this.joinPoint,retVal,null);
    }
}
